package com.spring.jackson.seckill.controller;

import com.spring.jackson.seckill.model.Goods;
import com.spring.jackson.seckill.service.GoodsService;
import com.spring.jackson.smvc.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * 秒杀返回页面Controller层
 */
@Controller
@RequestMapping(value = "/page/")
public class SeckillPageController {

    @Autowired
    private GoodsService goodsService;

    /**
     * 商品列表
     *
     * @param returnMap 返回页面数据
     * @return
     */
    @RequestMapping(value = "list")
    public String list(Map<String, Object> returnMap) {
        List<Goods> list = goodsService.getGoodsList();
        returnMap.put("list", list);
        return "list";
    }

    /**
     * 商品详情
     *
     * @param goodsId   商品id
     * @param returnMap 返回页面数据
     * @return
     */
    @RequestMapping(value = "{goodsId}/detail")
    public String detail(Integer goodsId, Map<String, Object> returnMap) {
        Goods detail = goodsService.getDetail(goodsId);
        returnMap.put("goods",detail);
        return "detail";
    }

}
